
<?php
$this->breadcrumbs = array(
	'Tickets' => array('/client/index'),
	'#' . $ticket->ticket_code => array('/client/view', 'ticket_code' => $ticket->ticket_code),
	'View Ticket'
);
?>
<?php $this->pageTitle = 'Manage Tickets'; ?>
<?php Yii::app()->clientScript->registerCssFile('/themes/adminica/css/hometicket.css'); ?>
	<div id="hometicket">
		<div id="header">
					<a id="logo" href="/index.php" title="Support Center"><img src="/logo.php" border="0" alt="congkhuong" style="height: 5em"></a>
					<p>
									  Guest User - <a href="/login.php">Log In</a>
								  </p>
		</div>
		<div class="flat_area">
			<ul id="nav">
				<li><a class="active home" href="<?php echo $this->createUrl('/tickets/client/index');?>">Support&nbsp;Center&nbsp;Home</a></li>
				<li><a class=" new" href="<?php echo $this->createUrl('/tickets/client/create');?>">Open&nbsp;New&nbsp;Ticket</a></li>
				<li><a class=" status" href="<?php echo $this->createUrl('/tickets/client/checkStatus');?>">Check Ticket Status</a></li>
			</ul>
		</div>
	</div>
<div class="main-title no-border clearfix">
	
	<div class="controls float-left">
		
	</div>
	
</div>
<div class="flat_area">
    <div class="grid_16 relative">
		<div class="section highlighted">
			<div class="block">
				<h4><strong><?php echo $ticket->subject; ?></strong></h4>
				<p>Added by <span class="blue"><?php echo $ticket->ticketUserCreate->username; ?></span> about <span class="blue"><?php echo DateFormatter::ago($ticket->create_time); ?></span></p>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						
						/*array(
							'label' => 'Escalation Level',
							'value' => $ticket->getCurrentEscalationLevel() ? $ticket->getCurrentEscalationLevel() : 'Not escalated'
						), */
						array(
							'label' => 'Closed By',
							'value' => $ticket->closed_by_user_id,
						//	'visible' => $ticket->isClosed()
						),
						array(
							'label' => 'Type',
							'name' => 'ticket_type_id',
							'value' => function($data){
								$buffer = TicketType::model()->findByPk($data->ticket_type_id);
								return $buffer->name;
							}
						),
						/*
						array(
							'type' => 'raw',
							'label' => $ticket->getReferenceLabel(),
							'value' => $ticket->reference
						),
						*/
						array(
							'label' => 'Create Date',
							'type' => 'raw',
							'value' => date("d-M-Y G:i:A", strtotime($ticket->create_time))
						),
						)));
				?>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						'name',
						'email',
						'subject'
						)));
				?>
				<hr/>
				<strong>Description</strong><br/>
				<?php echo $ticket->summary; ?>
			</div>
		</div>
	</div>
	<div class="grid_10">
		<div class="section">
			<div class="block">
				<h2>Responses</h2>
				<div class="grid-view grey">
					<table class="items" width="100%">
						<?php if (!empty($ticket->ticketResponses)): ?>
							<?php foreach ($ticket->ticketResponses as $ticketResponse): ?>
								<tr>
									<td>
										<strong><?php echo date("d M, Y @ G:iA", strtotime($ticketResponse->update_time)); ?></strong> <?php if ($ticketResponse->user_id != null) echo '-'.$ticketResponse->user->username;
										else echo 'Comment by create ticket user ';?><br/>
										<?php echo $ticketResponse->message; ?>
									</td>
								</tr>
							<?php endforeach; ?>
						<?php else: ?>
							<tr>
								<td>
									There are no responses to this ticket
								</td>
							</tr>
						<?php endif; ?>
					</table>
				</div>
			</div>
		</div>
		<div class="section">
			<div class="block">
				<h2>Comment</h2>
				<?php /* echo CHtml::dropDownList('selectTemplate', '2' , CHtml::listData(TicketTemplate::model()->findAllByAttributes(array('agency_id'=>$ticket->agency_id)), 'id', 'subject'),
					//array('prompt' => 'Select Template to Reply'),
					array(
						'prompt'=> 'Select a Template',
						'ajax' => array(
							'type'=>'POST',
							'url'=>CController::createUrl('/tickets/client/dynamicTemplate/'),
							'update'=>'#TicketResponse_message',
							//'data'=>'js:javascript statement',
						)
					)); */
				 ?>
				<?php
				$form = $this->beginWidget('CActiveForm', array(
					'id' => 'ticket-create-form',
					'enableAjaxValidation' => false,
						));
				?>
				<table class="form-table">
					<tr>
						<td>
							<?php echo $form->textArea($newTicketResponse, 'message', array('style' => 'width: 100%', 'rows' => '5', 'autocomplete' => 'off')); ?>
							<?php echo $form->error($newTicketResponse, 'message'); ?>
						</td>
					</tr>
				</table>
				<div class="row buttons">
					<?php echo CHtml::submitButton('Post Reply', array('class' => 'green')); ?>

					<?php //if ($ticket->ticket_type_id): ?>
						<?php echo CHtml::checkBox('alsoChangeStatus'); ?>
						Change status to:
						<?php echo $form->dropDownList($ticket, 'ticket_type_id', CHtml::listData(TicketStatusType::model()->findAll(), 'id', 'name'), array('prompt' => 'Select Type') ); ?>
					<?php //endif; ?>
				</div>
				<?php $this->endWidget(); ?>
			</div>
		</div>
    </div>
	<div class="grid_6">
		<div class="section">
			<div class="block">
				<h2>Status History</h2>
				<div class="grid-view grey">
					<table class="items" width="100%">
						<?php 
							$ticketStatusHistory = TicketStatusHistory::model()->findAllByAttributes(array('ticket_id'=> $ticket->id));
							//dump ($ticketStatusHistory );exit;
							if (!empty($ticketStatusHistory)): ?>
							<?php foreach ($ticketStatusHistory as $ticketStatus => $value): ?>
								<tr>
									<td>
										<?php echo date("d M, Y @ G:iA", strtotime($value->update_time)); ?>
									</td>
									<td>
										Set to <span class="blue"><strong><?php echo $value->ticketStatusType->name; ?></strong></span> by <span class="blue link"><?php echo $value->ticketChangeByUser->username; ?></span>
									</td>
								</tr>
							<?php endforeach; ?>
						<?php else: ?>
							<tr>
								<td>
									There are no responses to this ticket
								</td>
							</tr>
						<?php endif; ?>
					</table>
				</div>
			</div>
		</div>
		<?php if (!empty($ticket->escalations)): ?>
			<div class="section">
				<div class="block">
					<h2>Escalation History</h2>
					<div class="grid-view grey">
						<table class="items" width="100%">
							<?php foreach ($ticket->escalations as $escalation): ?>
								<tr>
									<td>
										<?php echo date("d M, Y @ G:iA", strtotime($escalation->escalation_time)); ?>
									</td>
									<td>
										<span class="blue">Escalated</span> to <span class="blue link"><?php echo $escalation->escalatedToUser->name; ?></span> <strong>(Level <?php echo $escalation->escalation_level; ?>)</strong>
									</td>
								</tr>
							<?php endforeach; ?>
						</table>
					</div>
				</div>
			</div>
		<?php endif; ?>
	</div>
</div>
<?php
$this->renderPartial('_dialog_escalate', array('ticket' => $ticket, 'escalation' => $escalation, 'ticketEscalationLevels' => $ticketEscalationLevels));
?>
